//
//  WMBaseTabBarController.swift
//  deWaterMarkingProject
//
//  Created by admin on 2025/9/5.
//

import UIKit

class WMBaseTabBarController: UITabBarController {

    var removeWaterVC: WMRemoveWaterMarkingController = WMRemoveWaterMarkingController()
    var imageWaterVC: WMImagesWatermarkedController = WMImagesWatermarkedController()
    var mineVC: WMMineController = WMMineController()
    
    override func viewDidLoad() {
        super.viewDidLoad()

        //移除顶部线条
        UITabBar.appearance().backgroundImage = UIImage.color(UIColor.clear)
        UITabBar.appearance().isTranslucent = false
        self.tabBar.backgroundImage = UIImage.color(UIColor.clear)
        self.tabBar.shadowImage = UIImage.color(UIColor.clear)
        //样式设置
        self.view.backgroundColor = UIColor.white
        self.tabBar.barTintColor = UIColor.white
        self.tabBar.isTranslucent = false
        self.tabBar.tintColor = UIColor(valueRGB: UInt(OEMInfo.themeHex), alpha: 1.0)
        
        addChildViewController(childController: removeWaterVC, title: "视频解析", imageName: "tabbar_remove_nor", selectedImageName: "tabbar_remove_sel")
        addChildViewController(childController: imageWaterVC, title: "图片AI消除", imageName: "tabbar_image_nor", selectedImageName: "tabbar_image_sel")
        addChildViewController(childController: mineVC, title: "我的", imageName: "tabbar_mine_nor", selectedImageName: "tabbar_mine_sel")
    }
    

    func addChildViewController(childController: UIViewController, title: String, imageName: String, selectedImageName: String) {

        childController.tabBarItem.image = UIImage(named: imageName)?.withRenderingMode(.alwaysOriginal)
        childController.tabBarItem.selectedImage = UIImage(named: selectedImageName)?.withRenderingMode(.alwaysOriginal)
        childController.title = title
        childController.tabBarItem.setTitleTextAttributes([NSAttributedString.Key.foregroundColor: UIColor(valueRGB: 0x999999, alpha: 1.0)], for: .normal)
        childController.tabBarItem.setTitleTextAttributes([NSAttributedString.Key.foregroundColor: UIColor(valueRGB: UInt(OEMInfo.themeHex), alpha: 1.0)], for: .selected)
        let nav = WMBaseNavigationController(rootViewController: childController)
        self.addChild(nav)
    }

    override func tabBar(_ tabBar: UITabBar, didSelect item: UITabBarItem) {
        requestEventSave(title: ["点击抖快去水印", "点击图片去水印", "点击我的"][selectedIndex], mode: ["点击抖快去水印", "点击图片去水印", "点击我的"][selectedIndex])
    }
    
}
